package com.oba.king.datalib.productinfo;

import java.util.Date;

import com.oba.base.dao.DBDataModel;
import com.oba.base.service.BaseBean;

public class ProductInfoBean extends BaseBean<ProductInfo,ProductInfoService> {

	private DBDataModel productInfoList = DBDataModel.create();
	private ProductInfo productInfo;
	private boolean showAddPrdt = false;
	private static final String ADD_NEW_PRDT_PATH = "/datalib/productInfoAdd.jspx";
	private static final String SHOW_PRDT_PATH = "/datalib/productInfoShow.jspx"; 
//	private String productName;
	private ProductCondition productCondition;


	@Override
	public String doFind() {
//		System.out.println("Start ProductInfoBean doFind()>>>>");
		this.productInfoList.find(this.getService().getDao().buildAll());
//		System.out.println("Start ProductInfoBean doFind()<<<<");
		return null;
	}

	@Override
	public void init() {
//		System.out.println("Start ProductInfoBean init()>>>>");
		this.productCondition = new ProductCondition();
		this.doFind();
//		System.out.println("End ProductInfoBean init()<<<<");
	}
	
	public void addNewPrdt(){
//		System.out.println("Start ProductInfoBean addNewPrdt()>>>>");
		this.productInfo = new ProductInfo();
		this.productInfo.setNewBo(true);
		this.goTarget(ADD_NEW_PRDT_PATH);
//		this.showAddPrdt = true;
//		System.out.println("End ProductInfoBean addNewPrdt()<<<<");
	}
	
	public void doEditPrdt(){
//		System.out.println("Start ProductInfoBean doEditPrdt()>>>>");
		if(this.productInfoList.isRowAvailable()){
			this.productInfo = (ProductInfo) this.productInfoList.getRowData();
			this.showAddPrdt = true;
			this.goTarget(ADD_NEW_PRDT_PATH);
		}
//		System.out.println("End ProductInfoBean doEditPrdt()<<<<");
	}
	
	public void doSavePrdt(){
//		System.out.println("Start ProductInfoBean doSavePrdt()>>>>");		
		if(this.productInfo.isNewBo()){
			this.productInfo.setCreateDate(new Date());
		}
		this.productInfo.setUpdateDate(new Date());
		this.getService().save(this.productInfo);
		this.showAddPrdt = false;
		this.goTarget(SHOW_PRDT_PATH);
		this.doFind();
//		System.out.println("End ProductInfoBean doSavePrdt()<<<<");
	}
	
	public void doDeletePrdt(){
//		System.out.println("Start ProductInfoBean doDeletePrdt()>>>>");
		if(this.productInfoList.isRowAvailable()){
			this.getService().del(this.productInfo);
			this.goTarget(SHOW_PRDT_PATH);
			this.doFind();
		}
//		System.out.println("End ProductInfoBean doDeletePrdt()<<<<");
	}
	
//	public void doSrchByPrdtNm(){
//		if(productName!=null && !productName.trim().equals("")){
//			this.productInfoList.find(this.getService().getDao().buildByCondition(productName),SHOW_ROW);
//		}
//	}
	
	/**
	 * 根据productCondition进行模糊查询
	 */
	public void srchProductCondition(){
		productInfoList.find(this.getService().getDao().srchProductCondition(productCondition));
	}
	
	/**
	 * 页面清除查询条件时
	 */
	public void cleanButton(){
		this.productCondition = new ProductCondition();
//		this.doFind();
	}
	
	public void doRturnShow(){
		this.goTarget(SHOW_PRDT_PATH);
		this.cleanButton();
	}

	public DBDataModel getProductInfoList() {
		return productInfoList;
	}

	public void setProductInfoList(DBDataModel productInfoList) {
		this.productInfoList = productInfoList;
	}

	public ProductInfo getProductInfo() {
		return productInfo;
	}

	public void setProductInfo(ProductInfo productInfo) {
		this.productInfo = productInfo;
	}
	
//	public String getProductName() {
//		return productName;
//	}
//
//	public void setProductName(String productName) {
//		this.productName = productName;
//	}


	public ProductCondition getProductCondition() {
		return productCondition;
	}

	public void setProductCondition(ProductCondition productCondition) {
		this.productCondition = productCondition;
	}

}
